home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1999-03-04 | 18.2 KB | 706 lines | [ TEXT/ToyS]
-- User setable properties property kasOpenWindowWhenRun : true -- Set to false to not open the remote item's window in the Finder when run property kasAllowAlerts : true -- Set to false to stop any alerts from appearing property kasServerAlerts : true -- Set to false to stop warnings about missed servers property kasFinder : "Finder" -- name of application to open RemoteLaunchers property kasAppendage : " ->" -- Appended to file name if we can't use original property kasPrefixLauncher : "≈ " -- Prefix named of launchers with these characters. -- Internal/User setable globals property gasLinkSet : false -- Has the friend been asked for? - set to true to never ask property gasLinkNeed : false property kasLinkUserDft : "CasaVision" -- Defaults for linking access property kasLinkPassDft : "" property gasServSet : false property gasServNeed : false property kasServUserDft : "Synapse" -- Defaults for server access property kasServPassDft : "" property kasServNTDft : "" -- Internal globals global gasLinkUser -- Our friend on all machines global gasLinkPass -- Our friend's password on all machines global gasServUser -- Our friend on all machines global gasServPass -- Our friend's password on all machines global gasServNT -- Volume password global gasStat -- Status window property gasOurAlias : "" -- The alias we own property gasOurStatus : "" -- Empty, "RemoteLauncher" or "RemoteFolder" property gasOurServer : "" -- Set to server of gasOurAlias property gasOurZone : "" -- Set to zone of gasOurAlias property gasOurName : "" -- Name of original alias property gasOurVol : "" -- Name of volume alias resides on property gasOurType : "" -- If we are a RemoteLauncher, this is our file type property gasCopyLoc : {-1, -1} -- The location of the copy window property gasStatLoc : {-1, -1} -- The location of the status window property kasStatName : "PowerScript V1.4" on run if (gasOurStatus is "") then ShowInitAlert() else if (gasOurStatus is "RemoteLauncher") then RunRemoteLauncher() else if (gasOurStatus is "RemoteFolder") then RunRemoteFolder(kasOpenWindowWhenRun) else beep end if end run on open fsObjs if option key down of (input state) then if the number of items in fsObjs is not 1 then ShowInitAlert() else if (ShowChoice("You have the option key pressed." & return & return & "Do you wish to reinitialize this script with the object you dropped on it?")) then SetScriptAlias(item 1 of fsObjs) end if else if (gasOurStatus is "") then if the number of items in fsObjs is not 1 then ShowInitAlert() else SetScriptAlias(item 1 of fsObjs) end if else if (gasOurStatus is "RemoteLauncher") then (* What we want to do here if the file dropped on us is on the same server as our alias: If we are a document and an application is dropped on us, we open us with that application. If we are an application and a document is dropped on us we open that document with this application. *) -- Get the user/password GetFriend(false) set cantOpen to false set iAmApp to (gasOurType is "APPL") repeat with fsObj in fsObjs set aInfo to alias info from fsObj if the alias server of aInfo is not gasOurServer then set cantOpen to true else set fInfo to basic info for fsObj set isAnApp to (system type of fInfo is "APPL") if (iAmApp is isAnApp) then set cantOpen to true else if (iAmApp) then set appAli to gasOurAlias set docAli to fsObj else set appAli to fsObj set docAli to gasOurAlias end if if (not RemoteLaunchUsing(appAli, docAli)) then return end if end if end repeat if (cantOpen) then ShowOpenAlert() else if (gasOurStatus is "RemoteFolder") then set wasMounted to IsVolMounted(gasOurVol) if (RunRemoteFolder(false)) then set replaceAll to false repeat with fsObj in fsObjs try set gasCopyLoc to ¬ (AkuaCopy fsObj located at gasCopyLoc with resuming given «class Dest»:gasOurAlias) on error err if (err contains "Duplicate") then set replaceOne to replaceAll set fsName to original name of (alias info from fsObj) if (not replaceOne) then set replaceChoice to ¬ ShowChoices("A file named “" & fsName & "” already exists." & return & ¬ return & "Do you wish to replace it?", {"Skip", "Replace", "Replace All"}) set replaceAll to replaceChoice is "Replace All" set replaceOne to replaceAll or (replaceChoice is "Replace") end if if (replaceOne) then try collate ((gasOurAlias as string) & fsName) as alias with the trasher -- Move it to Trash set gasCopyLoc to ¬ (AkuaCopy fsObj located at gasCopyLoc with resuming given «class Dest»:gasOurAlias) on error err ShowCopyAlert(fsObj, err) end try end if else ShowCopyAlert(fsObj, err) end if end try end repeat if (not wasMounted) then ¬ PutAwayVol(gasOurVol) end if end if end open on quit if ((the open windows) contains "Status") then ¬ set gasStatLoc to screen location of ¬ (display info gasStat with disposal) continue quit end quit on RunRemoteFolder(openInFinder) set mounted to true -- Get the user/password GetFriend(false) -- Mount the remote volume? if (gasOurServer is not "") then -- Local? ShowAction("Connecting to server") try mount server volume gasOurVol ¬ with volume password gasServNT on server gasOurServer ¬ in AppleTalk zone gasOurZone ¬ as user name gasServUser ¬ with password gasServPass ¬ on error ShowAction("Checking with remote Finder") if (CouldBeSharing(gasOurZone, gasOurServer)) then try mount server volume gasOurVol ¬ with volume password gasServNT on server gasOurServer ¬ in AppleTalk zone gasOurZone ¬ as user name gasServUser ¬ with password gasServPass ¬ on error errStr number errNum ShowAction("Couldn't mount it.") ShowError(errStr, errNum) if (kasServerAlerts) then ShowMountAlert() else beep end if set mounted to false end try else ShowStatus("Remote sharing could not be started.") if (kasServerAlerts) then ShowMountAlert() else beep end if set mounted to false end if end try end if if (mounted) then ShowAction("Finding folder") try set gfiDestFolder to ¬ resolve chain gasOurAlias ¬ with volume password gasServNT ¬ as user name gasServUser ¬ with password gasServPass -- Tell Finder to open the alias now that it is mounted ShowAction("Opening folder") if (openInFinder) then tell application kasFinder open gasOurAlias activate end tell end if on error errStr number errNum ShowError(errStr, errNum) set mounted to false if (kasServerAlerts) then ShowAliasAlert() else beep end if end try end if return mounted end RunRemoteFolder on RunRemoteLauncher() -- Get the user/password GetFriend(false) if (gasOurServer is not "") then -- Remote? talk as user gasLinkUser ¬ with password gasLinkPass ¬ on server gasOurServer ¬ in AppleTalk zone gasOurZone end if if (gasOurServer is "") then set suspect to application kasFinder else talk as user gasLinkUser ¬ with password gasLinkPass ¬ on server gasOurServer ¬ in AppleTalk zone gasOurZone set suspect to application kasFinder ¬ of machine gasOurServer ¬ of zone gasOurZone end if try -- Don't wait for a response, assume the aliases are correct tell suspect to open gasOurAlias on error errStr number errNum ShowError(errStr, errNum) ShowConnectAlert(kasFinder, errNum) end try end RunRemoteLauncher on RemoteLaunchUsing(appAli, docAli) set aName to original name of (alias info from appAli) -- Is the app running? if (gasOurServer is "") then -- Don't wait for a response, assume the aliases are correct tell application kasFinder ¬ to open docAli given «class usin»:appAli else talk as user gasLinkUser ¬ with password gasLinkPass ¬ on server gasOurServer ¬ in AppleTalk zone gasOurZone if (the server processes aName on server gasOurServer in AppleTalk zone gasOurZone ¬ as user name gasLinkUser with password gasLinkPass) is not "" then try tell application aName of machine gasOurServer ¬ of zone gasOurZone to open docAli on error err ShowConnectAlert(aName, err) end try else try -- Don't wait for a response, assume the aliases are correct tell application kasFinder of machine gasOurServer ¬ of zone gasOurZone to open docAli given «class usin»:appAli on error err ShowConnectAlert(kasFinder, err) return false end try end if end if return true end RemoteLaunchUsing on ChooseScriptAlias() if ShowChoices("Do you wish to activate this script with a folder/volume or a file?", {"Folder", "File"}) is "File" then set myObj to ¬ choose file with prompt "Choose a server file for this PowerScript RA" else set myObj to ¬ choose folder with prompt "Choose a server folder or volume for this PowerScript RA" end if SetScriptAlias(myObj) end ChooseScriptAlias on SetScriptAlias(aliasObj) -- My Path set myPath to (path to me) -- Grab an alias set gasOurAlias to aliasObj set aInfo to alias info from gasOurAlias set fInfo to basic info for gasOurAlias -- Save the info we need set gasOurServer to alias server of aInfo set gasOurZone to alias zone of aInfo set gasOurVol to alias volume of aInfo set gasOurName to original name of aInfo set gasOurType to system type of fInfo set newName to gasOurName -- Start with name of original item -- What will we be - a mounter or a launcher? if (catalog kind of fInfo) is a folder then set gasOurStatus to "RemoteFolder" set gasServNeed to true else set gasOurStatus to "RemoteLauncher" set gasLinkNeed to true set newName to kasPrefixLauncher & newName end if -- Try to set our name to dropped name try collate myPath renaming it to newName on error -- If we can't use the original name, try an appendage :) try collate myPath renaming it to newName & kasAppendage on error beep end try end try -- Get the user/password GetFriend(false) -- Set our icon to dropped icon set the icon of myPath to (the icon for gasOurAlias) with compatibility try tell application "Finder" to update myPath -- Double dose? on error beep end try end SetScriptAlias on GetFriend(override) -- Should later use some modifier key to override?!? set gasLinkUser to kasLinkUserDft set gasLinkPass to kasLinkPassDft set gasServUser to kasServUserDft set gasServPass to kasServPassDft set gasServNT to kasServNTDft if (gasOurServer is "") then -- Local? set gasLinkSet to true set gasServSet to true else -- Get linking (and server) user? if (gasLinkNeed) then GetOneFriend(true, override) -- Get server user? if (gasServNeed) then GetOneFriend(false, override) end if end GetFriend on GetOneFriend(isLink, override) if (isLink) then set userMode to "linking" if (gasLinkSet) then set defUser to gasLinkUser set defPass to gasLinkPass else set defUser to kasLinkUserDft set defPass to kasLinkPassDft end if set defNT to kasServNTDft -- Not used set passButtons to {"Cancel", "OK"} set passButton to 2 else set userMode to "sharing" if (gasServSet) then set defUser to gasServUser set defPass to gasServPass set defNT to gasServNT else set defUser to kasServUserDft set defPass to kasServPassDft set defNT to kasServNTDft end if set passButtons to {"Cancel", "NT Password…", "OK"} set passButton to 3 end if set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink) if (override or usrPwd is {}) then set chosen to display dialog ¬ "Enter the friendly " & userMode & ¬ " user's name for the server \"" & gasOurServer ¬ & "\"…" default answer defUser ¬ default button 2 with icon note if (the button returned of chosen is "OK") then set defUser to the text returned of chosen else return end if set chosen to display dialog ¬ "Enter the friendly " & userMode & ¬ " user's password…" buttons passButtons ¬ default answer defPass default button passButton with icon note if (the button returned of chosen is not "Cancel") then set defPass to the text returned of chosen else return end if if (the button returned of chosen is "NT Password…") then set chosen to display dialog ¬ "Enter the volume password for Windoze NT…" default answer ¬ defNT default button 2 with icon note if (the button returned of chosen is not "Cancel") then set gasServNT to the text returned of chosen else return end if end if -- Save encrypted user/pass for future access KeyChainSave(gasOurZone, gasOurServer, isLink, defUser, defPass, defNT) else set defUser to item 1 of usrPwd set defPass to item 2 of usrPwd set defNT to item 3 of usrPwd end if if (isLink) then set gasLinkSet to true set gasLinkUser to defUser set gasLinkPass to defPass else set gasServSet to true set gasServUser to defUser set gasServPass to defPass set gasServNT to defNT end if end GetOneFriend on PutAwayVol(volName) -- Volume try set vAlias to (vol alias of (the volume info of volume named volName)) eject vAlias on error beep end try end PutAwayVol on IsVolMounted(volName) -- Volume try set x to the volume info of volume named volName return true on error return false end try end IsVolMounted on CouldBeSharing(servZone, servName) GetOneFriend(true, false) -- Get linking user talk as user gasLinkUser ¬ with password gasLinkPass ¬ on server servName ¬ in AppleTalk zone servZone try set isOn to («class fshr» ¬ of application kasFinder ¬ of machine servName ¬ of zone servZone) if (not isOn) then set «class fshr» of application kasFinder ¬ of machine servName ¬ of zone servZone to true ShowAction("Wait for Sharing") set waitSecs to 333 repeat while not («class fshr» of application kasFinder ¬ of machine servName ¬ of zone servZone) ShowStatus("Wait another " & waitSecs & " seconds.") pause for 120 set waitSecs to waitSecs - 2 if (waitSecs < 1) then exit repeat end repeat if («class fshr» of application kasFinder ¬ of machine servName ¬ of zone servZone) then ShowStatus("It is up!") else ShowStatus("Can't get it up!") beep end if return («class fshr» of application ¬ kasFinder of machine servName of zone servZone) end if on error errStr if (errStr contains "-911") then GetOneFriend(true, true) return CouldBeSharing() end if end try return false end CouldBeSharing on ShowAliasAlert() if ShowChoices("Couldn't resolve alias for " & gasOurName & ¬ " on " & gasOurVol & " from machine " & gasOurServer & ¬ "." & return & return & "Would you like to reset it?", ¬ {"Refind item", "No"}) is not "No" then ¬ ChooseScriptAlias() end ShowAliasAlert on ShowMountAlert() ShowServerAlert("Couldn't mount volume " & gasOurVol & ¬ " from " & gasOurServer ¬ & " in zone " & gasOurZone) end ShowMountAlert on ShowConnectAlert(appName, err) if (not kasServerAlerts) then beep else ShowServerAlert("Couldn't connect to " & appName & " on " & ¬ gasOurServer & " in zone " & gasOurZone & return & return & "Error: " & err) end if end ShowConnectAlert on ShowServerAlert(msg) if ShowChoices(msg, {"Reenter Password", "OK"}) ¬ is not "OK" then ¬ GetFriend(true) end ShowServerAlert on ShowInitAlert() if ShowChoices("This script must first be activated by dropping exactly one item on it." & ¬ return & return & "Please see the information file that accompanied it.", ¬ {"Activate", "OK"}) is not "OK" then ¬ ChooseScriptAlias() end ShowInitAlert on ShowOpenAlert() ShowAlert("This script is currently in Launcher mode and can thus not process any files dropped on it." & ¬ return & return & "To reconfigure the script, open it with ScriptEditor and save it.") end ShowOpenAlert on ShowCopyAlert(fsObj, err) ShowAlert("An error (" & (err as string) & ") occured copying “" & ¬ (original name of (alias info from fsObj)) & "”." & return & return & ¬ "The network may have been interrupted or a disk error may have occured") end ShowCopyAlert on ShowAlert(msgStr) if (kasAllowAlerts) then display dialog msgStr buttons {"Damn!"} ¬ default button 1 with icon caution else beep end if end ShowAlert on ShowChoice(msgStr) return (ShowChoices(msgStr, {"No", "Yes"}) is "Yes") end ShowChoice on ShowChoices(msgStr, choices) set choice to ¬ display dialog msgStr buttons choices ¬ default button (number of items of choices) ¬ with icon stop return (button returned of choice) end ShowChoices on StatusNew() if ((the open windows) contains kasStatName) then return display info titled kasStatName else set gasStat to display info titled kasStatName end if end StatusNew on ShowAction(msg) StatusNew() display info gasStat message msg at line 1 ¬ using bg color (20 * 1024 + 20 * 32 + 31) end ShowAction on ShowStatus(msg) StatusNew() display info gasStat message msg at line 2 ¬ using bg color (20 * 1024 + 31 * 32 + 20) end ShowStatus on ShowError(errMsg, errNum) StatusNew() display info gasStat message (errMsg & " (" & errNum & ")") at line 3 ¬ using bg color (31 * 1024 + 20 * 32 + 20) pause for 120 end ShowError property kasKeyChainPassword : "PowerScript" -- Encrypt stored data with this property kasPrefsFileName : "PowerScript Prefs" -- File name in <Preferences> on KeyChainLookUp(zoneName, serverName, isLinking) set prefType to "πSRV" if (isLinking) then set prefType to "πLNK" try set myKeyData to load preference of type prefType ¬ named (zoneName & ":" & serverName) ¬ in file named kasPrefsFileName on error return {} end try return (encrypt the data myKeyData ¬ with password kasKeyChainPassword) end KeyChainLookUp on KeyChainSave(zoneName, serverName, isLinking, usr, pwd, ntPwd) set myKey to encrypt the data {usr, pwd, ntPwd} ¬ with password kasKeyChainPassword set prefType to "πSRV" if (isLinking) then set prefType to "πLNK" save preference myKey of type prefType ¬ named (zoneName & ":" & serverName) ¬ in file named kasPrefsFileName end KeyChainSave